home *** CD-ROM | disk | FTP | other *** search
/ Point Programming 1 / PPROG1.ISO / pascal / swag / printing.swg / 0038_Printing Graphics.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1994-08-25  |  4.5 KB  |  138 lines

  1. {
  2. From: randyd@alpha2.csd.uwm.edu (Randall Elton Ding)
  3.  
  4. >How do you get an Epson-compatible 24-pin printer to print graphics?
  5. >Printing text is simple... just open the appropriate LPT port and
  6. >redirect text into it.
  7. >
  8. >I suppose if I had a manual for the printer I could find out what any of
  9. >the escape codes are.
  10.  
  11. Here is a routine I wrote years ago
  12. for my old Epson MX-100 (made in early 80's)
  13. You should get some ideas from this program, it may even be capable
  14. of being modified to work with your printer.
  15. I don't know if the escape codes are the same, you'll have to
  16. look them up.  BTW, this printer is a 9 pin and only 8 are used.
  17. Thats convenient because each print head pass generates 8 pixils high
  18. per character sent.  I don't know how your 24 pin works.
  19. }
  20.  
  21. program develop;  { developed for Epson MX-100 and EGA screen }
  22.  
  23. uses graph;
  24.  
  25. const
  26.   rotate90= true;
  27.   widepaper= false;
  28.   bgipath: string = 'e:\bp\bgi';
  29.  
  30.  
  31. procedure initbgi;
  32.   var
  33.     errcode,grdriver,grmode: integer;
  34.  
  35.   begin
  36.     grdriver := Detect;
  37.     initgraph(grdriver,grmode,bgipath);
  38.     errcode:= graphresult;
  39.     if errcode <> grok then begin
  40.       writeln('Graphics error: ',grapherrormsg (errcode));
  41.       halt(1);
  42.     end;
  43.   end;
  44.  
  45.  
  46.  
  47. procedure developgraph(rotate: boolean);
  48.                             { if passed parameter is true, the graphics
  49.                               image will be rotated 90 degrees to fit on
  50.                               a narrow sheet of printer paper, if false
  51.                               the image will completely fill the wide
  52.                               paper erect and double height }
  53.  
  54.   const maxprinter = 816; { maximum width of printer }
  55.  
  56.   var
  57.     graphwidth,graphheight,printerwidth,printerheight: integer;
  58.     n1,n2,sx,sy,x,y,y2,pixcolr: integer;
  59.     widthratio,heightratio: real;
  60.     blank: boolean;
  61.     bitloc,bits: byte;
  62.     bytes: array [1..maxprinter] of byte;
  63.     lst: text;
  64.  
  65.   begin
  66.     assign(lst,'lpt1');
  67.     rewrite(lst);
  68.     case rotate of
  69.       widepaper: begin                       { develop erect on wide paper }
  70.                    graphwidth:= getmaxx+1;
  71.                    graphheight:= getmaxy+1;
  72.                    printerwidth:= maxprinter;       { scale 1.275 x 2 }
  73.                    printerheight:= graphheight*2;
  74.                  end;
  75.       rotate90:  begin                     { if rotate then reverse x and y }
  76.                    graphwidth:= getmaxy+1;
  77.                    graphheight:= getmaxx+1;
  78.                    printerwidth:= graphwidth;       { scale 1 x 1 }
  79.                    printerheight:= graphheight;
  80.                  end;
  81.     end;
  82.     n2:= printerwidth div 256;
  83.     n1:= printerwidth mod 256;
  84.     write(lst,chr(27),'A',chr(8));   { set line spacing to 8 }
  85.     widthratio:= printerwidth/graphwidth;
  86.     heightratio:= printerheight/graphheight;
  87.     y:= 0;
  88.     while y < printerheight do begin
  89.       blank:= true;    { remains true if entire printer pass is blank }
  90.       for x:= 1 to printerwidth do begin
  91.         sx:= trunc((x-1)/widthratio);  { screen x coorid }
  92.         bits:= 0;
  93.         bitloc:= $80;
  94.         for y2:= y to y+7 do begin
  95.           sy:= trunc(y2/heightratio);  { screen y coorid }
  96.           if sy < graphheight then begin { last printer pass is incomplete }
  97.             case rotate of
  98.               widepaper: pixcolr:= getpixel(sx,sy);
  99.               rotate90:  pixcolr:= getpixel(sy,sx);   { x and y swaped }
  100.             end;
  101.             if pixcolr > 0 then bits:= bits or bitloc;
  102.           end;
  103.           bitloc:= bitloc shr 1;
  104.         end;
  105.         case rotate of
  106.           widepaper: bytes[x]:= bits;
  107.           rotate90:  bytes[printerwidth-x+1]:= bits;  { reverse image }
  108.         end;
  109.         if bits > 0 then blank:= false; { have something to print this pass }
  110.       end;
  111.       if not blank then begin    { line feed if nothing to print this pass }
  112.         write (lst,chr(27),'K',chr(n1),chr(n2));  { set printer graph mode }
  113.         for x:= 1 to printerwidth do write (lst,chr(bytes[x]));
  114.       end;
  115.       writeln(lst);   { output 8 printer pixels high per pass }
  116.       y:= y+8;
  117.     end;
  118.     write(lst,chr(12));       { top of form }
  119.     write(lst,chr(27),'@');   { re-initalize printer }
  120.     close(lst);
  121.   end;
  122.  
  123.  
  124. begin
  125.   initbgi;
  126.  
  127.   { your graphics code here }
  128.   Line(100,100,200,100);
  129.   Line(200,100,200,100);
  130.   Line(100,200,200,100);
  131.   Line(100,100,200,200);
  132.   SetColor(Blue);
  133.   Circle(300,200,50);
  134.  
  135.   developgraph(rotate90);    { or use (widepaper) }
  136. end.
  137.  
  138.